package org.linlinjava.litemall.db.service;

import org.linlinjava.litemall.db.dao.LitemallGoodsAttributeMapper;
import org.linlinjava.litemall.db.domain.LitemallGoodsAttribute;
import org.linlinjava.litemall.db.domain.LitemallGoodsAttributeExample;
import org.linlinjava.litemall.db.mapper.LitemallGoodsAttributeDao;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class LitemallGoodsAttributeService {
    @Resource
    private LitemallGoodsAttributeDao goodsAttributeDao;

    public List<LitemallGoodsAttribute> queryByGid(Integer goodsId) {
    	
    	LitemallGoodsAttribute entity = new LitemallGoodsAttribute();
    	entity.setGoodsId(goodsId);
    	entity.setDeleted(false);
    	return goodsAttributeDao.template(entity);
		/*
		 * LitemallGoodsAttributeExample example = new LitemallGoodsAttributeExample();
		 * example.or().andGoodsIdEqualTo(goodsId).andDeletedEqualTo(false); return
		 * goodsAttributeMapper.selectByExample(example);
		 */
    }

    public void add(LitemallGoodsAttribute goodsAttribute) {
        goodsAttribute.setAddTime(LocalDateTime.now());
        goodsAttribute.setUpdateTime(LocalDateTime.now());
        goodsAttributeDao.insertTemplate(goodsAttribute,true);
        //goodsAttributeMapper.insertSelective(goodsAttribute);
    }

    public LitemallGoodsAttribute findById(Integer id) {
    	return goodsAttributeDao.single(id);
        //return goodsAttributeMapper.selectByPrimaryKey(id);
    }

    public void deleteByGid(Integer gid) {
    	
    	LitemallGoodsAttribute entity = new LitemallGoodsAttribute();
    	entity.setGoodsId(gid);
    	entity.setDeleted(true);
    	goodsAttributeDao.updateTemplateById(entity);
        /*LitemallGoodsAttributeExample example = new LitemallGoodsAttributeExample();
        example.or().andGoodsIdEqualTo(gid);
        goodsAttributeMapper.logicalDeleteByExample(example);*/
    }

    public void deleteById(Integer id) {
    	LitemallGoodsAttribute entity = new LitemallGoodsAttribute();
    	entity.setId(id);
    	entity.setDeleted(true);
    	goodsAttributeDao.updateTemplateById(entity);
        //goodsAttributeMapper.logicalDeleteByPrimaryKey(id);
    }

    public void updateById(LitemallGoodsAttribute attribute) {
        attribute.setUpdateTime(LocalDateTime.now());
        goodsAttributeDao.updateTemplateById(attribute);
        //goodsAttributeMapper.updateByPrimaryKeySelective(attribute);
    }
}
